package se.webbzon.boltzmann.game.object.spawner;

import se.webbzon.boltzmann.environment.AbstractEnvironment;
import se.webbzon.boltzmann.game.region.RegionObject;
import se.webbzon.boltzmann.game.sequence.Sequences;
import se.webbzon.boltzmann.resource.Resources;
import se.webbzon.oschi01.worldeditor.DeflatableWorldObject;
import se.webbzon.oschi01.worldobject.WorldObject;
import se.webbzon.oschi01.worldobject.WorldStaticObject;
import se.webbzon.oschi01.worldobject.appearance.Appearance3D;
import se.webbzon.oschi01.worldobject.appearance.CubeAppearance3D;
import se.webbzon.oschi01.worldobject.appearance.SimpleAppearance3D;

public abstract class AbstractSpawner extends WorldStaticObject implements DeflatableWorldObject, RegionObject {
	
	// The name of the deflatable world object
	private final String worldObjectName;
	
	// The unique id of the spawner
	private long id;
	
	// The key name used as assignment condition
	private String key;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new abstract spawner. **/
	public AbstractSpawner(String worldObjectName, long id, String key) {
		super(0,createAppearance());
		this.worldObjectName = worldObjectName;
		this.id = id;
		setKey(key);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Spawns a new instance. If a new instance could not be created
	 * then null is returned. **/
	public abstract WorldObject spawn(AbstractEnvironment env);
	
	/** Returns the name of the key used as assignment condition. **/
	public String getKey() {
		return key;
	}
	
	/** Sets the name of the key used as assignment condition. **/
	public void setKey(String key) {
		this.key = Sequences.withPrefix(key,false);
	}
	
	@Override public String getName() {
		return worldObjectName;
	}
	
	@Override public long getId() {
		return id;
	}
	
	@Override public void setId(long id) {
		this.id = id;
	}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Creates the spawner appearance. **/
	private static final Appearance3D createAppearance() {
		SimpleAppearance3D appearance = new CubeAppearance3D();
		appearance.setTextureSet(Resources.getTextureSet("misc_unknown"));
		return appearance;
	}

}
